package com.groupscore.score.controller;

import com.alibaba.fastjson.JSON;
import com.groupscore.score.pojo.Rycl;
import com.groupscore.score.service.RyclService;
import entity.Result;
import entity.StatusCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("/rycl")
public class RyclController {
    @Autowired
    private RyclService ryclService;

    @PostMapping
    public Result add(@RequestBody Rycl rycl){
        ryclService.add(rycl);
        return new Result(true, StatusCode.OK, "新增成功");
    }

    /**
     * 字符串转map
     */
    @PostMapping(value = "/save")
    public Result save(@RequestBody Map message){

        System.out.println(message);
        System.out.println(message.get("resourceName"));
        Rycl rycl = JSON.parseObject(message.get("resourceName")+"", Rycl.class);//json字符串转对象
        System.out.println(rycl);

        return new Result(true, StatusCode.OK, "新增成功");
    }
}
